package org.example.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Dingdan;
import org.example.result.Result;
import org.example.service.DingdanService;
import org.example.service.PinjiaService;
import org.example.service.ShanpinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dingdan")
@Slf4j
@Api(tags = "订单相关接口")
public class EmployeedingdanController {

    @Autowired
    DingdanService dingdanService;
    @Autowired
    PinjiaService pinjiaService;
    @Autowired
    private ShanpinService shanpinService;

    /**
     * 新增订单
     * @param dingdan
     * @return
     */
    @PostMapping("/xz")
    @ApiOperation(value = "新增订单")
    public Result submitPayment(@RequestBody Dingdan dingdan) {
        log.info("订单{}",dingdan);
        dingdanService.xz(dingdan);
        return Result.success();
    }

    /**
     * 付款查询
     * @param username
     * @return
     */
    @GetMapping("/fkcx")
    @ApiOperation(value = "付款查询")
    public Result<List<Dingdan>> fkcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,0));
    }


    /**
     * 付款修改
     * @param
     * @return
     */
    @PutMapping("/fkxg")
    @ApiOperation(value = "付款修改")
    public Result fkxg(@RequestParam( "id") int id){

        dingdanService.xg(id,1);
        return Result.success();
    }

    /**
     * 付款删除
     * @param
     * @return
     */
    @DeleteMapping("/fksc")
    @ApiOperation(value = "付款删除")
    public Result fksc(@RequestParam( "id") int id){

        dingdanService.sc(id);
        return Result.success();
    }

    /**
     * 发货查询
     * @param username
     * @return
     */
    @GetMapping("/fhcx")
    @ApiOperation(value = "发货查询")
    public Result<List<Dingdan>> fhcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,1));
    }

    /**
     * 收货查询
     * @param username
     * @return
     */
    @GetMapping("/shouhcx")
    @ApiOperation(value = "收货查询")
    public Result<List<Dingdan>> shouhcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,2));
    }

    /**
     * 收货修改
     * @param
     * @return
     */
    @PutMapping("/shouhxg")
    @ApiOperation(value = "收货修改")
    public Result shouhxg(@RequestParam( "id") int id
    ,@RequestParam( "shanpinid") int shanpinid){

        dingdanService.xg(id,3);
        shanpinService.xgshu(shanpinid);
        return Result.success();
    }

    /**
     * 退款修改
     * @param
     * @return
     */
    @PutMapping("/tuihxg")
    @ApiOperation(value = "退款修改")
    public Result tuihxg(@RequestParam( "id") int id,@RequestParam( "tuih") String tuih){

        dingdanService.xgxz(id,5,tuih);
        return Result.success();
    }


    /**
     * 评价查询
     * @param username
     * @return
     */
    @GetMapping("/pjcx")
    @ApiOperation(value = "评价查询")
    public Result<List<Dingdan>> pjcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,3));
    }

    /**
     * 评价修改
     * @param
     * @return
     */
    @PutMapping("/pjxg")
    @ApiOperation(value = "评价修改")
    public Result pjxg(@RequestParam( "id") int id){

        dingdanService.xg(id,4);
        return Result.success();
    }


    /**
     * 评价查询
     * @param username
     * @return
     */
    @GetMapping("/ypjcx")
    @ApiOperation(value = "已评价查询")
    public Result<List<Dingdan>> ypjcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,4));
    }


    /**
     * 评价删除
     * @param
     * @return
     */
    @DeleteMapping("/pjsc")
    @ApiOperation(value = "评价删除")
    public Result pjsc(@RequestParam( "id") int id){
        dingdanService.sc(id);
        pinjiaService.sc(id);
        return Result.success();
    }


    /**
     * 退款查询
     * @param username
     * @return
     */
    @GetMapping("/tkcx")
    @ApiOperation(value = "退款查询")
    public Result<List<Dingdan>> tkcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,5));
    }

    /**
     * 退款修改
     * @param
     * @return
     */
    @PutMapping("/tkxg")
    @ApiOperation(value = "退款修改")
    public Result tkxg(@RequestParam( "id") int id){

        dingdanService.xg(id,2);
        return Result.success();
    }


    /**
     * 退款查询
     * @param username
     * @return
     */
    @GetMapping("/clcx")
    @ApiOperation(value = "处理查询")
    public Result<List<Dingdan>> clcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.cx(username,6));
    }


    /**
     * 数目查询
     * @param username
     * @return
     */
    @GetMapping("/shucx")
    @ApiOperation(value = "数目查询")
    public Result<List<Integer>> shumcx(@RequestParam( "username") String username){

        return Result.success(dingdanService.shumcx(username));
    }

    /**
     * 处理删除
     * @param
     * @return
     */
    @DeleteMapping("/clsc")
    @ApiOperation(value = "处理删除")
    public Result clsc(@RequestParam( "id") int id){
        dingdanService.clsc(id,0);
        return Result.success();
    }
}
